package top.hiai.Controller.admin;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

import top.hiai.model.Comment;
import top.hiai.service.CommentService;
import top.hiai.util.FormatjsonUtil;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top,开发者：黄康权
* @Introduction 后台用户评论控制器
*/

public class AdminCommentController extends Controller {
	CommentService commentService = new CommentService();
	/**
	 * 后台遍历评论的列表
	 */
	public void commentListTable(){
    	String s_name = get("name");
		//获取用户的ID
        Integer page = getParaToInt("page", 1);
        Integer limit = getParaToInt("limit", 10);
        Page<Comment> paginate = commentService.paginateAdmin(page, limit,s_name);
        renderJson(FormatjsonUtil.layuiPage(paginate));
	}
	/**
	 * 后台修改评论是否显示
	 */
	public void updateCommentState(){
		int cid = getInt("cid");
		boolean state = getBoolean("state");
		int sstate;
		if(state){
			sstate = 1;
		}else{
			sstate = 0;
		}
		System.out.println("id是:"+cid+",hot:"+state);
		boolean resuleId = getModel(Comment.class).setCid(cid).setState(sstate).update();
		if(resuleId){
			renderJson("success",true);
		}else{
			renderJson("success",false);
		}
	}
	
	/**
	 * 后台评论删除
	 */
	public void deleteComment(){
		commentService.deleteById(getParaToInt());
		redirect("/admin/adminCommentManage");
	}
}
